//
//  RequesURL.m
//  LO_MUSIC
//
//  Created by 胡林 on 16/2/25.
//  Copyright © 2016年 杨少锋. All rights reserved.
//

#import "RequesURL.h"
@class MusicMode;
#define kHomeUrl @"http://project.lanou3g.com/teacher/UIAPI/MusicInfoList.plist"
@implementation RequesURL
//音乐首页的请求
-(void)requestMusiclistWithSuccess:(void(^)(id item))success faile:(void(^)(NSError *err))faile{
    //开辟子线程
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        //请求数据
        NSArray * arr = [NSArray arrayWithContentsOfURL:[NSURL URLWithString:kHomeUrl]];
        
        //如果请求的数据为空
        if (arr.count == 0) {
            NSError * err =[NSError errorWithDomain:@"请求出错" code:0 userInfo:nil];
            //回主线程
            dispatch_async(dispatch_get_main_queue(), ^{
                faile(err);
                return ;
            });
        }
        //创建一个数组盛放模型对象
        NSMutableArray * modelArray = [NSMutableArray array];

        //解析
        for (NSDictionary * dic in arr) {
            MusicMode * model = [[MusicMode alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelArray addObject:model];
        }
        //判断block是否存在
        if (success) {
            dispatch_async(dispatch_get_main_queue(), ^{
                 success(modelArray);
            });
        }
    });
}


/*
- (MusicMode *)musicModelWithIndex:(NSInteger)index
{
    if (index < 0 || index >= self.allDataMutableArray.count) {
        return nil;
    }
    return self.allDataMutableArray[index];
}

*/

#pragma mark - 重写
/**
 *  获取数据的getter方法
 
- (NSArray *)allDataArray
{
    return [self.allDataMutableArray copy];
}




#pragma mark - 懒加载
- (NSMutableArray *)allDataMutableArray
{
    if (!_allDataMutableArray) {
        self.allDataMutableArray = [NSMutableArray new];
    }
    return _allDataMutableArray;
}

*/


@end

@implementation MusicMode

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}

@end








